package com.yipinhouse.reception.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.reception.client.IntentionMoneyWebClient;
import com.yipinhouse.reception.client.param.IntentionMoneyWebParam;
import com.yipinhouse.signing.client.IntentionMoneyManageClient;
import com.yipinhouse.signing.client.param.IntentionMoneyParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("reception")

public class IntentionMoneyApiImpl implements IntentionMoneyWebClient {


    @Resource
    private IntentionMoneyManageClient intentionMoneyManageClient;


    /**
     * 新增意向金
     */
    @Override
    public Result insertIntentionMoney(IntentionMoneyWebParam intentionMoneyParam) throws InterruptedException {
        IntentionMoneyParam intentionMoneyParams = BeanUtil.copyProperties(intentionMoneyParam, IntentionMoneyParam.class);
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId1 = request.getHeader("userId");
        Integer userId = Integer.valueOf(userId1);
        intentionMoneyParams.setUserId(userId);
        Result result = intentionMoneyManageClient.insertIntentionMoney(intentionMoneyParams);
        return result;
    }

}
